import { _decorator, Component, director, Label, Node } from "cc";
const { ccclass, property } = _decorator;

@ccclass("GameOverUI")
export class GameOverUI extends Component {
  @property(Label)
  curScoreLabel: Label = null;
  @property(Label)
  bestScoreLabel: Label = null;

  @property(Node)
  newSprite: Node = null;

  @property([Node])
  medalArray: Node[] = [];
  public show(curScore: number, bestScore: number) {
    this.node.active = true;
    this.curScoreLabel.string = curScore.toString();
    this.bestScoreLabel.string = bestScore.toString();
    if (curScore > bestScore) {
      this.newSprite.active = true;
    } else {
      this.newSprite.active = false;
    }

    const index = curScore / 10
    let medalIndex = Math.min(Math.floor(index), 3)
    this.medalArray[medalIndex].active = true
  }

  hide() {
    this.node.active = false;
  }

  onPlayButtonClick() {
    director.loadScene('FLAPPYBIRD')
  }
}
